package team.zero.lemon.module.cms.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import team.zero.lemon.common.authz.annotation.AuthPassport;
import team.zero.lemon.common.authz.annotation.AuthPermission;
import team.zero.lemon.common.persistence.Page;
import team.zero.lemon.common.web.BaseController;
import team.zero.lemon.module.cms.entity.Article;
import team.zero.lemon.module.cms.entity.Audit;
import team.zero.lemon.module.cms.service.ArticleService;
import team.zero.lemon.module.cms.service.AuditService;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by bolin on 2016/10/24.
 */
@Controller
@ResponseBody
@AuthPassport
@RequestMapping(value = "/cms/article", method = {RequestMethod.POST, RequestMethod.GET})
public class ArticleController  extends BaseController {
    @Autowired
    private ArticleService articleService;
    @Autowired
    private AuditService auditService;
    @AuthPassport
    @RequestMapping("/query/page")
    public Page<Article> findArticle(@RequestBody Article article) {
        return articleService.findPage(article);
    }
    @AuthPassport
    @RequestMapping("/query/view/page")
    public Page<Article> findViewPage(@RequestBody Article article) {
        return articleService.findViewPage(article);
    }

    @AuthPassport
    @RequestMapping("/save")
    public int SaveArticle(HttpServletRequest request, @RequestBody Article article) {
        return articleService.saveArticle(request,article);
    }

    @AuthPassport
    @RequestMapping("/delete/ids")
    public int deleteArticle(@RequestBody Article article) {
        return articleService.deleteLogicMulti(article);
    }
    @AuthPassport
    @RequestMapping("/query/all")
    public List<Article> findAllArticles() {
        return articleService.findAll();
    }

    @AuthPassport
    @RequestMapping("/query/articleid")
    public Article findArticleByArticleId(@RequestBody Article article) {
        return articleService.findByArticleId(article);
    }
    @AuthPassport
    @RequestMapping("/audit/query/articleid")
    public List<Audit> findAuditByArticleId(@RequestBody Audit audit) {
        return auditService.findByArticleId(audit.getArticleId(),audit.getAuditType());
    }
}
